package com.example.quce.controller;

import com.example.quce.common.R;
import com.example.quce.entity.FunnyResult;
import com.example.quce.mapper.FunnyResultMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/funny")
@RequiredArgsConstructor
public class FunnyResultController {
    @Autowired
    FunnyResultMapper funnyResultMapper;

    @GetMapping("/selectAllResult")
    public R selectAllResult() {
        // 读取funnyresult表中所有数据
        List<FunnyResult> resultList=this.funnyResultMapper.selectAllResult();
        // 把从数据库中读取的结果打印到ApiPost中（前端）
        return R.ok(resultList);
    }

    // 根据id查询测试结果
    @GetMapping("/selectResultById/{id}")
    public R selectResultById(@PathVariable("id") int id) {
        FunnyResult funnyResult=new FunnyResult();
        funnyResult=this.funnyResultMapper.selectResultById(id);
        return R.ok(funnyResult);
    }

    // 根据test_id查询测试结果
    @GetMapping("/selectResultByTest/{test_id}")
    public R selectResultByTest(@PathVariable("test_id") int test_id) {
        //FunnyResult funnyResult=new FunnyResult();
        List<FunnyResult> resultList=this.funnyResultMapper.selectResultByTest(test_id);
        return R.ok(resultList);
    }

    // 根据id查询测试结果
    @PostMapping("/selectResultByRT")
    public R selectResultByRT(@RequestBody FunnyResult funnyResult) {
        FunnyResult Result=funnyResultMapper.selectResultByRT(funnyResult.getResult_id(),funnyResult.getTest_id());
        return R.ok(Result);
    }

}
